home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / games1 / break.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-23  |  31.0 KB  |  853 lines

  1. VERSION 4.00
  2. Begin VB.Form frmBreakThru 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    BorderStyle     =   0  'None
  6.    Caption         =   "BREAK-THRU!"
  7.    ClientHeight    =   5265
  8.    ClientLeft      =   2670
  9.    ClientTop       =   2025
  10.    ClientWidth     =   3810
  11.    BeginProperty Font 
  12.       name            =   "MS Sans Serif"
  13.       charset         =   0
  14.       weight          =   700
  15.       size            =   8.25
  16.       underline       =   0   'False
  17.       italic          =   0   'False
  18.       strikethrough   =   0   'False
  19.    EndProperty
  20.    ForeColor       =   &H00000000&
  21.    Height          =   5955
  22.    Icon            =   "BREAK.frx":0000
  23.    KeyPreview      =   -1  'True
  24.    Left            =   2610
  25.    LinkTopic       =   "Form1"
  26.    MaxButton       =   0   'False
  27.    MinButton       =   0   'False
  28.    ScaleHeight     =   5265
  29.    ScaleWidth      =   3810
  30.    ShowInTaskbar   =   0   'False
  31.    Top             =   1395
  32.    Width           =   3930
  33.    Begin VB.Timer JoyTimer 
  34.       Interval        =   22
  35.       Left            =   3060
  36.       Top             =   5280
  37.    End
  38.    Begin VB.PictureBox picPaddle 
  39.       Appearance      =   0  'Flat
  40.       AutoRedraw      =   -1  'True
  41.       AutoSize        =   -1  'True
  42.       BackColor       =   &H80000005&
  43.       BorderStyle     =   0  'None
  44.       ForeColor       =   &H80000008&
  45.       Height          =   180
  46.       Left            =   1320
  47.       Picture         =   "BREAK.frx":030A
  48.       ScaleHeight     =   12
  49.       ScaleMode       =   3  'Pixel
  50.       ScaleWidth      =   30
  51.       TabIndex        =   6
  52.       Top             =   5460
  53.       Visible         =   0   'False
  54.       Width           =   450
  55.    End
  56.    Begin VB.PictureBox picBlack 
  57.       Appearance      =   0  'Flat
  58.       AutoRedraw      =   -1  'True
  59.       BackColor       =   &H00000000&
  60.       FillStyle       =   0  'Solid
  61.       ForeColor       =   &H80000008&
  62.       Height          =   495
  63.       Left            =   270
  64.       ScaleHeight     =   465
  65.       ScaleWidth      =   675
  66.       TabIndex        =   8
  67.       Top             =   5190
  68.       Visible         =   0   'False
  69.       Width           =   705
  70.    End
  71.    Begin VB.PictureBox picBall 
  72.       Appearance      =   0  'Flat
  73.       AutoRedraw      =   -1  'True
  74.       AutoSize        =   -1  'True
  75.       BackColor       =   &H80000005&
  76.       BorderStyle     =   0  'None
  77.       ForeColor       =   &H80000008&
  78.       Height          =   120
  79.       Left            =   1110
  80.       Picture         =   "BREAK.frx":044C
  81.       ScaleHeight     =   8
  82.       ScaleMode       =   3  'Pixel
  83.       ScaleWidth      =   8
  84.       TabIndex        =   7
  85.       Top             =   5520
  86.       Visible         =   0   'False
  87.       Width           =   120
  88.    End
  89.    Begin VB.PictureBox picField 
  90.       Appearance      =   0  'Flat
  91.       BackColor       =   &H00000000&
  92.       ClipControls    =   0   'False
  93.       ForeColor       =   &H80000008&
  94.       Height          =   3975
  95.       Left            =   135
  96.       ScaleHeight     =   263
  97.       ScaleMode       =   3  'Pixel
  98.       ScaleWidth      =   234
  99.       TabIndex        =   0
  100.       Tag             =   "/3d/"
  101.       Top             =   1140
  102.       Width           =   3540
  103.       Begin VB.Label lblGameOver 
  104.          Alignment       =   2  'Center
  105.          Appearance      =   0  'Flat
  106.          BackColor       =   &H80000005&
  107.          BackStyle       =   0  'Transparent
  108.          Caption         =   "GAME OVER"
  109.          BeginProperty Font 
  110.             name            =   "MS Sans Serif"
  111.             charset         =   0
  112.             weight          =   400
  113.             size            =   12
  114.             underline       =   0   'False
  115.             italic          =   0   'False
  116.             strikethrough   =   0   'False
  117.          EndProperty
  118.          ForeColor       =   &H000000FF&
  119.          Height          =   315
  120.          Left            =   -30
  121.          TabIndex        =   2
  122.          Top             =   1260
  123.          Visible         =   0   'False
  124.          Width           =   3525
  125.       End
  126.       Begin VB.Image imgBlock 
  127.          Appearance      =   0  'Flat
  128.          Height          =   210
  129.          Index           =   0
  130.          Left            =   1080
  131.          Picture         =   "BREAK.frx":04EE
  132.          Top             =   480
  133.          Visible         =   0   'False
  134.          Width           =   300
  135.       End
  136.       Begin VB.Label lblPaused 
  137.          Alignment       =   2  'Center
  138.          Appearance      =   0  'Flat
  139.          BackColor       =   &H80000005&
  140.          BackStyle       =   0  'Transparent
  141.          Caption         =   "PAUSED"
  142.          BeginProperty Font 
  143.             name            =   "MS Sans Serif"
  144.             charset         =   0
  145.             weight          =   400
  146.             size            =   12
  147.             underline       =   0   'False
  148.             italic          =   0   'False
  149.             strikethrough   =   0   'False
  150.          EndProperty
  151.          ForeColor       =   &H000000FF&
  152.          Height          =   315
  153.          Left            =   0
  154.          TabIndex        =   12
  155.          Top             =   1740
  156.          Visible         =   0   'False
  157.          Width           =   3525
  158.       End
  159.    End
  160.    Begin VB.Timer Timer1 
  161.       Enabled         =   0   'False
  162.       Interval        =   5
  163.       Left            =   2520
  164.       Top             =   5280
  165.    End
  166.    Begin VB.Label lblHiScore 
  167.       Alignment       =   2  'Center
  168.       Appearance      =   0  'Flat
  169.       BackColor       =   &H80000005&
  170.       BackStyle       =   0  'Transparent
  171.       Caption         =   "0000"
  172.       BeginProperty Font 
  173.          name            =   "MS Sans Serif"
  174.          charset         =   0
  175.          weight          =   700
  176.          size            =   9.75
  177.          underline       =   0   'False
  178.          italic          =   0   'False
  179.          strikethrough   =   0   'False
  180.       EndProperty
  181.       ForeColor       =   &H000000FF&
  182.       Height          =   255
  183.       Left            =   1620
  184.       TabIndex        =   11
  185.       Tag             =   "/3d/"
  186.       Top             =   540
  187.       Width           =   1875
  188.    End
  189.    Begin VB.Label Label4 
  190.       Alignment       =   1  'Right Justify
  191.       Appearance      =   0  'Flat
  192.       BackColor       =   &H80000005&
  193.       BackStyle       =   0  'Transparent
  194.       Caption         =   "High Score:"
  195.       BeginProperty Font 
  196.          name            =   "MS Sans Serif"
  197.          charset         =   0
  198.          weight          =   700
  199.          size            =   9.75
  200.          underline       =   0   'False
  201.          italic          =   0   'False
  202.          strikethrough   =   0   'False
  203.       EndProperty
  204.       ForeColor       =   &H00FF0000&
  205.       Height          =   255
  206.       Left            =   240
  207.       TabIndex        =   10
  208.       Top             =   540
  209.       Width           =   1275
  210.    End
  211.    Begin VB.Label lblPoints 
  212.       Alignment       =   1  'Right Justify
  213.       Appearance      =   0  'Flat
  214.       BackColor       =   &H80000005&
  215.       BackStyle       =   0  'Transparent
  216.       Caption         =   "0000"
  217.       BeginProperty Font 
  218.          name            =   "MS Sans Serif"
  219.          charset         =   0
  220.          weight          =   700
  221.          size            =   12
  222.          underline       =   0   'False
  223.          italic          =   0   'False
  224.          strikethrough   =   0   'False
  225.       EndProperty
  226.       ForeColor       =   &H000000FF&
  227.       Height          =   315
  228.       Left            =   1140
  229.       TabIndex        =   3
  230.       Top             =   150
  231.       Width           =   675
  232.    End
  233.    Begin VB.Label Label2 
  234.       Alignment       =   1  'Right Justify
  235.       Appearance      =   0  'Flat
  236.       BackColor       =   &H80000005&
  237.       BackStyle       =   0  'Transparent
  238.       Caption         =   "Points:"
  239.       BeginProperty Font 
  240.          name            =   "MS Sans Serif"
  241.          charset         =   0
  242.          weight          =   700
  243.          size            =   12
  244.          underline       =   0   'False
  245.          italic          =   0   'False
  246.          strikethrough   =   0   'False
  247.       EndProperty
  248.       ForeColor       =   &H00FF0000&
  249.       Height          =   315
  250.       Left            =   240
  251.       TabIndex        =   5
  252.       Top             =   150
  253.       Width           =   885
  254.    End
  255.    Begin VB.Label Label1 
  256.       Alignment       =   1  'Right Justify
  257.       Appearance      =   0  'Flat
  258.       BackColor       =   &H80000005&
  259.       BackStyle       =   0  'Transparent
  260.       Caption         =   "Balls Used:"
  261.       BeginProperty Font 
  262.          name            =   "MS Sans Serif"
  263.          charset         =   0
  264.          weight          =   700
  265.          size            =   12
  266.          underline       =   0   'False
  267.          italic          =   0   'False
  268.          strikethrough   =   0   'False
  269.       EndProperty
  270.       ForeColor       =   &H00FF0000&
  271.       Height          =   315
  272.       Left            =   1830
  273.       TabIndex        =   4
  274.       Top             =   150
  275.       Width           =   1485
  276.    End
  277.    Begin VB.Label lblMisses 
  278.       Alignment       =   1  'Right Justify
  279.       Appearance      =   0  'Flat
  280.       BackColor       =   &H80000005&
  281.       BackStyle       =   0  'Transparent
  282.       Caption         =   "0"
  283.       BeginProperty Font 
  284.          name            =   "MS Sans Serif"
  285.          charset         =   0
  286.          weight          =   700
  287.          size            =   12
  288.          underline       =   0   'False
  289.          italic          =   0   'False
  290.          strikethrough   =   0   'False
  291.       EndProperty
  292.       ForeColor       =   &H000000FF&
  293.       Height          =   315
  294.       Left            =   3240
  295.       TabIndex        =   1
  296.       Top             =   150
  297.       Width           =   285
  298.    End
  299.    Begin VB.Label Label3 
  300.       Appearance      =   0  'Flat
  301.       BackColor       =   &H80000005&
  302.       BackStyle       =   0  'Transparent
  303.       ForeColor       =   &H80000008&
  304.       Height          =   795
  305.       Left            =   120
  306.       TabIndex        =   9
  307.       Tag             =   "/3d/"
  308.       Top             =   120
  309.       Width           =   3525
  310.    End
  311.    Begin VB.Menu mnuPlay 
  312.       Caption         =   "&Play"
  313.       Begin VB.Menu mnuPlayNewGame 
  314.          Caption         =   "&New Game"
  315.          Shortcut        =   {F2}
  316.       End
  317.       Begin VB.Menu mnuPauseGame 
  318.          Caption         =   "&Pause"
  319.          Shortcut        =   {F3}
  320.       End
  321.       Begin VB.Menu mnuPlaySep1 
  322.          Caption         =   "-"
  323.       End
  324.       Begin VB.Menu mnuPlayExit 
  325.          Caption         =   "E&xit"
  326.          Shortcut        =   ^X
  327.       End
  328.    End
  329. Attribute VB_Name = "frmBreakThru"
  330. Attribute VB_Creatable = False
  331. Attribute VB_Exposed = False
  332. Option Explicit
  333. '--------------------------------------------------
  334. ' Global constants and varaibles used within the
  335. ' game's main form.
  336. '--------------------------------------------------
  337. ' Ball Information --------------------------------
  338. Dim bmpBall As tBitMap
  339. ' The current ball speed
  340. Dim XSpeed As Integer
  341. Dim YSpeed As Integer
  342. ' The slowest allowable ball speed
  343. Dim MinXSpeed As Integer
  344. Dim MinYSpeed As Integer
  345. ' The units at which the ball speed can change
  346. Dim SpeedUnit As Integer
  347. ' Either +1 or -1, determines the direction
  348. ' that the ball is moving
  349. Dim Xdir As Integer
  350. Dim YDir As Integer
  351. ' The starting position of the ball.
  352. Dim XStartBall As Integer
  353. Dim YStartBall As Integer
  354. Dim NumBalls As Integer
  355. ' Paddle Information ------------------------------
  356. Dim bmpPaddle As tBitMap
  357. ' The starting position of the paddle
  358. Dim XStartPaddle As Integer
  359. Dim YStartPaddle As Integer
  360. ' The current amount of "english" that the paddle
  361. ' will apply to the ball.
  362. Dim PaddleEnglish As Integer
  363. ' The amount that the paddle will move.
  364. Dim PaddleIncrement As Integer
  365. ' Block Information -------------------------------
  366. Const BLOCKS_IN_ROW = 10
  367. Const NUM_ROWS = 2
  368. Const BLOCK_GAP = 3
  369. ' Strings that store game wave audio files in memory.
  370. Dim wavPaddleHit As String
  371. Dim wavBlockHit As String
  372. Dim wavWall As String
  373. Dim wavMissed As String
  374. Dim wavSetup As String
  375. Dim wavNewLevel As String
  376. ' Use JoyStick?
  377. Dim UseJoystick As Integer
  378. ' Joystick Information
  379. Dim JoyInfo As tJoyInfo
  380. Dim JoyAtRestMin As Long
  381. Dim JoyAtRestMax As Long
  382. ' Used when calling the two API functions below.
  383. Const SECTION = "HiScore"
  384. Const ENTRY = "Score"
  385. Const INI_FILE = "BREAKTHR.INI"
  386. Dim HiScore As Integer
  387. Dim HiPlayer As String
  388. ' Boolean (True/False) value that indicates if game
  389. ' has been paused.
  390. Dim Paused As Integer
  391. Private Sub Bitmap_Move(ABitMap As tBitMap, ByVal NewLeft As Integer, ByVal NewTop As Integer, SourcePicture As PictureBox)
  392. '--------------------------------------------------
  393. ' This routine uses the BitBlt API function to
  394. ' first remove a bitmap from its original location
  395. ' (by simply BitBlting a black rectangle over its
  396. ' current position), then BitBlting the picture
  397. ' to its new location.
  398. '--------------------------------------------------
  399. Dim retcode As Integer
  400.     ' Cover the image with a black rectangle, erasing it.
  401.     retcode = BitBlt(picField.hDC, ABitMap.Left, ABitMap.Top, ABitMap.Width, ABitMap.Height, picBlack.hDC, 0, 0, SRCCOPY)
  402.     ' Update the images location in its data structure.
  403.     ABitMap.Left = NewLeft
  404.     ABitMap.Top = NewTop
  405.     ' Redisplay it at its new location.
  406.     retcode = BitBlt(picField.hDC, ABitMap.Left, ABitMap.Top, ABitMap.Width, ABitMap.Height, SourcePicture.hDC, 0, 0, SRCCOPY)
  407. End Sub
  408. Private Function BlockCollided(A As tBitMap, B As Image) As Integer
  409. '--------------------------------------------------
  410. ' Check if the bitmap, A, and the image control, B,
  411. ' overlap each other.
  412. '--------------------------------------------------
  413. Dim ACenterY As Integer
  414. Dim BCenterY As Integer
  415. Dim ACenterX As Integer
  416. Dim BCenterX As Integer
  417.     ACenterY = (A.Height \ 2) + A.Top
  418.     BCenterY = (B.Height \ 2) + B.Top
  419.     ACenterX = (A.Width \ 2) + A.Left
  420.     BCenterX = (B.Width \ 2) + B.Left
  421.     BlockCollided = False
  422.     ' See if they intersect in the same Y range
  423.     If Abs(ACenterY - BCenterY) < ((A.Height + B.Height) \ 2) Then
  424.         ' See if the intersect in the same X range
  425.         If Abs(ACenterX - BCenterX) < ((A.Width + B.Width) \ 2) Then
  426.             BlockCollided = True
  427.         End If
  428.     End If
  429. End Function
  430. Private Function Collided(A As tBitMap, B As tBitMap) As Integer
  431. '--------------------------------------------------
  432. ' Check if the two rectangles (bitmaps) intersect,
  433. ' using the IntersectRect API call.
  434. '--------------------------------------------------
  435. ' Although we won't use it, we need a result
  436. ' rectangle to pass to the API routine.
  437. Dim ResultRect As tBitMap
  438.     ' Calculate the right and bottoms of rectangles needed by the API call.
  439.     A.Right = A.Left + A.Width - 1
  440.     A.Bottom = A.Top + A.Height - 1
  441.     B.Right = B.Left + B.Width - 1
  442.     B.Bottom = B.Top + B.Height - 1
  443.     ' IntersectRect will only return 0 (false) if the
  444.     ' two rectangles do NOT intersect.
  445.     Collided = IntersectRect(ResultRect, A, B)
  446. End Function
  447. Private Sub CreateBlocks()
  448. '--------------------------------------------------
  449. ' Create all the imgBlock elements that we need.
  450. '--------------------------------------------------
  451. Dim i As Integer
  452.     For i = 1 To (NUM_ROWS * BLOCKS_IN_ROW)
  453.         Load imgBlock(i)
  454.     Next
  455. End Sub
  456. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  457. '--------------------------------------------------
  458. ' All game play input is handled through the
  459. ' keyboard (left and right arrow keys).
  460. '--------------------------------------------------
  461.     Select Case KeyCode
  462.         Case KEY_LEFT:
  463.             ' Make sure we're not off the left side
  464.             If (bmpPaddle.Left - PaddleIncrement) > 0 Then
  465.                 ' Move the paddle to the left.
  466.                 Bitmap_Move bmpPaddle, bmpPaddle.Left - PaddleIncrement, bmpPaddle.Top, picPaddle
  467.                 ' Discard any english the paddle might have had from the opposite direction.
  468.                 If PaddleEnglish > 0 Then PaddleEnglish = 0
  469.                 PaddleEnglish = PaddleEnglish - 1
  470.             End If
  471.         Case KEY_RIGHT:
  472.             ' Make sure we're not off the right side.
  473.             If (bmpPaddle.Left + bmpPaddle.Width + PaddleIncrement) < picField.ScaleWidth Then
  474.                 ' Move the paddle to the right.
  475.                 Bitmap_Move bmpPaddle, bmpPaddle.Left + PaddleIncrement, bmpPaddle.Top, picPaddle
  476.                 ' Discard any english the paddle might have had from the opposite direction.
  477.                 If PaddleEnglish < 0 Then PaddleEnglish = 0
  478.                 PaddleEnglish = PaddleEnglish + 1
  479.             End If
  480.     End Select
  481. End Sub
  482. Private Sub Form_Load()
  483. '--------------------------------------------------
  484. ' Position the game form and initialize all game
  485. ' values
  486. '--------------------------------------------------
  487. Dim JoyXRange As Long
  488. Dim JoyXCenter As Long
  489. Dim rc As Integer
  490. Dim ScoreStr As String
  491.     Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
  492.     ' Display the form.
  493.     Me.Show
  494.     InitGeneralGameData
  495.     CreateBlocks
  496.     ' Read the current High Score.
  497.     HiScore = 0
  498.     HiPlayer = "???"
  499.     ScoreStr = Space$(25)
  500.     rc = GetPrivateProfileString(SECTION, ENTRY, "", ScoreStr, Len(ScoreStr), INI_FILE)
  501.     If rc > 0 Then
  502.         ScoreStr = Left$(ScoreStr, rc)
  503.         If IsNumeric(ScoreStr) Then HiScore = Val(ScoreStr)
  504.         HiPlayer = Space$(255)
  505.         rc = GetPrivateProfileString(SECTION, "Player", "", HiPlayer, Len(HiPlayer), INI_FILE)
  506.         If rc > 0 Then
  507.             HiPlayer = Left$(HiPlayer, rc)
  508.         Else
  509.             HiPlayer = "???"
  510.         End If
  511.     End If
  512.     ' Set up the Joystick
  513.     rc = GetJoyStickPos(JOYSTICK1, JoyInfo)
  514.     JoyXRange = (JoyCaps.Xmax - JoyCaps.Xmin)
  515.     JoyXCenter = JoyCaps.Xmin + (JoyXRange / 2)
  516.     JoyAtRestMin = JoyXCenter - (JoyXRange * 0.08)
  517.     JoyAtRestMax = JoyXCenter + (JoyXRange * 0.08)
  518.     ' Boolean (True/False) value that indicates if game
  519.     ' has been paused.
  520.     Paused = False
  521. End Sub
  522. Private Sub Form_Paint()
  523. '--------------------------------------------------
  524. ' Draw 3D effect around selected controls on form.
  525. '--------------------------------------------------
  526. Dim i As Integer
  527.     On Error Resume Next
  528.     ' Look at the tag fields of all controls
  529.     For i = 0 To Me.Controls.Count - 1
  530.         If InStr(UCase$(Me.Controls(i).Tag), "/3D/") Then
  531.             Make3D Me, Me.Controls(i), BORDER_INSET
  532.         ElseIf InStr(UCase$(Me.Controls(i).Tag), "/3DUP/") Then
  533.             Make3D Me, Me.Controls(i), BORDER_RAISED
  534.         End If
  535.     Next
  536. End Sub
  537. Private Sub InitGeneralGameData()
  538. '--------------------------------------------------
  539. ' Set up variables that don't change during game play.
  540. '--------------------------------------------------
  541.     ' Determine the ball's start position based on game board dimensions.
  542.     XStartBall = (picField.ScaleWidth - picBall.ScaleWidth) / 2
  543.     YStartBall = (picField.ScaleHeight) / 4
  544.     ' Determine the paddle's start position based on game board dimensions.
  545.     XStartPaddle = (picField.ScaleWidth - picPaddle.ScaleWidth) / 2
  546.     YStartPaddle = picField.ScaleHeight - picPaddle.ScaleHeight
  547.     ' Load all the Game sounds into memory.
  548.     wavSetup = NoiseGet(App.Path & "\" & "setup.wav")
  549.     wavPaddleHit = NoiseGet(App.Path & "\" & "paddle.wav")
  550.     wavBlockHit = NoiseGet(App.Path & "\" & "blockhit.wav")
  551.     wavWall = NoiseGet(App.Path & "\" & "wallhit.wav")
  552.     wavMissed = NoiseGet(App.Path & "\" & "missed.wav")
  553.     wavNewLevel = NoiseGet(App.Path & "\" & "newlevel.wav")
  554.     ' Get Ball dimensions from the picBall control
  555.     bmpBall.Left = XStartBall
  556.     bmpBall.Top = YStartBall
  557.     bmpBall.Width = picBall.ScaleWidth
  558.     bmpBall.Height = picBall.ScaleHeight
  559.     ' Get Paddle dimensions from the picPaddle control
  560.     bmpPaddle.Left = XStartPaddle
  561.     bmpPaddle.Top = YStartPaddle
  562.     bmpPaddle.Width = picPaddle.ScaleWidth
  563.     bmpPaddle.Height = picPaddle.ScaleHeight
  564.                   
  565.     ' Number of balls the user gets during the game.
  566.     NumBalls = 4
  567. End Sub
  568. Private Sub InitNewGameData()
  569. '--------------------------------------------------
  570. ' Set up all the variable we need for a new game.
  571. '--------------------------------------------------
  572.     ' Reset the score counting labels.
  573.     lblHiScore = Format$(HiScore, "0000") & " - " & Trim$(HiPlayer)
  574.     lblMisses = 0
  575.     lblPoints = "0000"
  576.     ' Turn off the "Game Over" sign.
  577.     lblGameOver.Visible = False
  578.     ' The slowest speed increment is one pixel.
  579.     SpeedUnit = 1
  580.     ' Set the minimum speed.
  581.     MinXSpeed = SpeedUnit * 6
  582.     MinYSpeed = MinXSpeed
  583.     ' Initial Speed is as slow as allowable.
  584.     XSpeed = MinXSpeed
  585.     YSpeed = MinYSpeed
  586.     ' Move ball to starting position.
  587.     ResetBall
  588.     ' Make sure the playing field is clear.
  589.     picField.Cls
  590.     ' Draw the paddle on the playing field.
  591.     Bitmap_Move bmpPaddle, bmpPaddle.Left, bmpPaddle.Top, picPaddle
  592.     ' Set up the initial state of the paddle.
  593.     PaddleEnglish = 0
  594.     PaddleIncrement = 7
  595. End Sub
  596. Private Sub JoyTimer_Timer()
  597. '--------------------------------------------------
  598. '--------------------------------------------------
  599. Dim rc As Integer
  600.     If Not UseJoystick Then Exit Sub
  601.     rc = GetJoyStickPos(JOYSTICK1, JoyInfo)
  602.     If JoyInfo.X < JoyAtRestMin Then
  603.         ' Make sure we're not off the left side
  604.         If (bmpPaddle.Left - PaddleIncrement) > 0 Then
  605.             ' Move the paddle to the left.
  606.             Bitmap_Move bmpPaddle, bmpPaddle.Left - PaddleIncrement, bmpPaddle.Top, picPaddle
  607.             ' Discard any english the paddle might have had from the opposite direction.
  608.             If PaddleEnglish > 0 Then PaddleEnglish = 0
  609.             PaddleEnglish = PaddleEnglish - 1
  610.         End If
  611.     ElseIf JoyInfo.X > JoyAtRestMax Then
  612.         ' Make sure we're not off the right side.
  613.         If (bmpPaddle.Left + bmpPaddle.Width + PaddleIncrement) < picField.ScaleWidth Then
  614.             ' Move the paddle to the right.
  615.             Bitmap_Move bmpPaddle, bmpPaddle.Left + PaddleIncrement, bmpPaddle.Top, picPaddle
  616.             ' Discard any english the paddle might have had from the opposite direction.
  617.             If PaddleEnglish < 0 Then PaddleEnglish = 0
  618.             PaddleEnglish = PaddleEnglish + 1
  619.         End If
  620.     End If
  621. End Sub
  622. Private Sub MissedBall()
  623. '--------------------------------------------------
  624. ' Move the ball back to its starting position.
  625. '--------------------------------------------------
  626. Dim answer As String
  627. Dim rc As Integer
  628.     ' Suspend game play
  629.     Timer1.Enabled = False
  630.     ' Play the "Missed Ball" sound.
  631.     NoisePlay wavMissed, SND_SYNC
  632.     ' Update the number of balls missed.
  633.     lblMisses = lblMisses + 1
  634.     ' If there are more balls left, continue playing.
  635.     If lblMisses < NumBalls Then
  636.         ResetBall
  637.         Timer1.Enabled = True
  638.     ' if no balls left, the game is over.
  639.     Else
  640.         lblGameOver.Visible = True
  641.         mnuPlayNewGame.Enabled = True
  642.         If IsNumeric(lblPoints) Then
  643.             If lblPoints > HiScore Then
  644.                 answer = InputBox$("Congratulations! This is a new HIGH SCORE! Enter Your Name:", "Great Game!")
  645.                 rc = WritePrivateProfileString(SECTION, "Player", answer, INI_FILE)
  646.                 rc = WritePrivateProfileString(SECTION, ENTRY, Format$(lblPoints), INI_FILE)
  647.                 HiScore = lblPoints
  648.                 HiPlayer = Trim$(answer)
  649.                 lblHiScore = Format$(HiScore, "0000") & " - " & Trim$(HiPlayer)
  650.             End If
  651.         End If
  652.     End If
  653. End Sub
  654. Private Sub mnuPauseGame_Click()
  655.     Paused = Not Paused
  656.     If Paused Then
  657.         lblPaused.Visible = True
  658.     Else
  659.         lblPaused.Visible = False
  660.     End If
  661. End Sub
  662. Private Sub mnuPlayExit_Click()
  663. '--------------------------------------------------
  664. ' Exit the program.
  665. '--------------------------------------------------
  666.     Unload Me
  667. End Sub
  668. Private Sub mnuPlayNewGame_Click()
  669. '--------------------------------------------------
  670. ' When this menu item is selected, the program
  671. ' initializes and sets up a new game.
  672. '--------------------------------------------------
  673. Dim retcode As Integer
  674.     ' Disable this menu option so a new game can't
  675.     ' be started when one is in progress.
  676.     mnuPlayNewGame.Enabled = False
  677.     ' Initialize the data needed for a new game.
  678.     InitNewGameData
  679.     ' Set up the game for the first level.
  680.     SetupNextLevel
  681. End Sub
  682. Private Sub ResetBall()
  683. '--------------------------------------------------
  684. ' Move the ball back to its starting position,
  685. ' and reset the starting ball direction.
  686. '--------------------------------------------------
  687.     ' The ball always starts out going down and right.
  688.     Xdir = 1
  689.     YDir = 1
  690.     ' Move the ball to the starting position.
  691.     bmpBall.Left = XStartBall
  692.     bmpBall.Top = YStartBall
  693. End Sub
  694. Private Sub SetupBlocks()
  695. '--------------------------------------------------
  696. ' Setup the blocks between each round of game play.
  697. '--------------------------------------------------
  698. Dim XIncr As Integer
  699. Dim i As Integer
  700. Dim j As Integer
  701. Dim ArrPos As Integer
  702.       
  703.     ' Make sure any visible blocks are hidden.
  704.     For j = 1 To (NUM_ROWS * BLOCKS_IN_ROW)
  705.         imgBlock(j).Visible = False
  706.         DoEvents
  707.     Next
  708.     XIncr = imgBlock(0).Width + BLOCK_GAP
  709.     imgBlock(0).Top = BLOCK_GAP
  710.     For j = 1 To NUM_ROWS
  711.         For i = 1 To BLOCKS_IN_ROW
  712.             ' Translate a 2-dimensional position to a 1-D array index.
  713.             ArrPos = ((j - 1) * BLOCKS_IN_ROW) + i
  714.             ' Place the block...
  715.             imgBlock(ArrPos).Move BLOCK_GAP + ((i - 1) * XIncr), imgBlock(0).Top
  716.             ' and make it visible.
  717.             imgBlock(ArrPos).Visible = True
  718.             ' Make a noise each time a block is displayed.
  719.             NoisePlay wavSetup, SND_SYNC
  720.             ' DoEvents makes sure that the screen has a chance to update
  721.             ' between sounds.
  722.             DoEvents
  723.         Next
  724.         ' Calculate the new row position
  725.         imgBlock(0).Top = imgBlock(0).Top + imgBlock(0).Height + BLOCK_GAP
  726.     Next
  727. End Sub
  728. Private Sub SetupNextLevel()
  729. '--------------------------------------------------
  730. ' Each time the user moves to a new level (after
  731. ' clearing all the blocks at the current level)
  732. ' the blocks must be replaced and the
  733. '--------------------------------------------------
  734. Dim retcode As Integer
  735.     ' Suspend game play.
  736.     Timer1.Enabled = False
  737.     ' Hide the ball
  738.     retcode = BitBlt(picField.hDC, bmpBall.Left, bmpBall.Top, bmpBall.Width, bmpBall.Height, picBlack.hDC, 0, 0, SRCCOPY)
  739.     ' Put a fresh set of blocks on the screen.
  740.     retcode = sndPlaySound(App.Path & "\" & "newlevel.wav", SND_SYNC)
  741.     SetupBlocks
  742.     ' Put the ball back at its starting position.
  743.     ResetBall
  744.     ' Resume game play.
  745.     Timer1.Enabled = True
  746. End Sub
  747. Private Sub Timer1_Timer()
  748. '--------------------------------------------------
  749. ' This event handles most of the game action, with
  750. ' the exception of paddle movement, which is
  751. ' handled by the form's Key_Down event.
  752. '--------------------------------------------------
  753. Dim Xinc As Integer
  754. Dim Yinc As Integer
  755. Dim i As Integer
  756. Dim PaddleCollision As Integer
  757. Static MoreBlocks As Integer
  758. Static PrevPaddleCollision As Integer
  759.     If Paused Then Exit Sub
  760.     ' Determine how much, and in which direction, to move the ball.
  761.     Xinc = Xdir * XSpeed
  762.     Yinc = YDir * YSpeed
  763.     ' Ball will hit the left wall
  764.     If (bmpBall.Left + bmpBall.Width + Xinc) > picField.ScaleWidth Then
  765.         Xdir = -Xdir
  766.         Xinc = Xdir * XSpeed
  767.         NoisePlay wavWall, SND_ASYNC
  768.     End If
  769.     ' Ball will hit the right wall
  770.     If (bmpBall.Left + Xinc) < 0 Then
  771.         Xdir = -Xdir
  772.         Xinc = Xdir * XSpeed
  773.         NoisePlay wavWall, SND_ASYNC
  774.     End If
  775.     ' Ball got past paddle (at the bottom of playing field)
  776.     If (bmpBall.Top) > picField.ScaleHeight Then
  777.         MissedBall
  778.     End If
  779.     ' Ball hit the back (top) wall
  780.     If (bmpBall.Top + Yinc) < 0 Then
  781.         YDir = -YDir
  782.         Yinc = YDir * YSpeed
  783.         NoisePlay wavWall, SND_ASYNC
  784.     End If
  785.     ' Check if the paddle and ball collided.
  786.     PaddleCollision = Collided(bmpBall, bmpPaddle)
  787.     ' Move the ball to its new position
  788.     Bitmap_Move bmpBall, bmpBall.Left + Xinc, bmpBall.Top + Yinc, picBall
  789.     ' If the paddle is hit, then redraw the paddle.
  790.     If PaddleCollision Then
  791.         Bitmap_Move bmpPaddle, bmpPaddle.Left, bmpPaddle.Top, picPaddle
  792.     End If
  793.     ' See if we've hit the paddle...
  794.     If PaddleCollision And (Not PrevPaddleCollision) Then
  795.         YDir = -Abs(YDir)
  796.         
  797.         ' Adjust ball dynamics for paddle english
  798.         If Abs(PaddleEnglish) > 0 Then
  799.             If PaddleEnglish > 0 Then
  800.                 If Xdir > 0 Then
  801.                     ' Speed it up.
  802.                     XSpeed = XSpeed + SpeedUnit
  803.                 Else
  804.                     ' Slow it down.
  805.                     XSpeed = XSpeed - SpeedUnit
  806.                     ' Reverse the ball's X direction.
  807.                     Xdir = -Xdir
  808.                 End If
  809.             ElseIf PaddleEnglish < 0 Then
  810.                 If Xdir < 0 Then
  811.                     ' Speed it up.
  812.                     XSpeed = XSpeed + SpeedUnit
  813.                 Else
  814.                     ' Slow it down.
  815.                     XSpeed = XSpeed - SpeedUnit
  816.                     ' Reverse the ball's X direction.
  817.                     Xdir = -Xdir
  818.                 End If
  819.             End If
  820.             ' Don't let the ball go too slow
  821.             If XSpeed < MinXSpeed Then XSpeed = MinXSpeed
  822.         End If
  823.         ' Play the paddle hit noise.
  824.         NoisePlay wavPaddleHit, SND_ASYNC
  825.     ' See if the ball collided with the blocks.
  826.     ElseIf bmpBall.Top < ((NUM_ROWS + 1) * imgBlock(0).Height) Then
  827.         MoreBlocks = False
  828.         For i = 1 To (NUM_ROWS * BLOCKS_IN_ROW)
  829.             If imgBlock(i).Visible Then
  830.                 MoreBlocks = True
  831.                 If BlockCollided(bmpBall, imgBlock(i)) Then
  832.                     ' "Turn off", or hide, this block.
  833.                     imgBlock(i).Visible = False
  834.                     ' If we hit a block, send the ball back down.
  835.                     YDir = Abs(YDir)
  836.                     ' Play the block hit noise.
  837.                     NoisePlay wavBlockHit, SND_ASYNC
  838.                     ' The player gets a point for each block hit.
  839.                     lblPoints = Format$(Val(lblPoints) + 1, "0000")
  840.                 End If
  841.             End If
  842.         Next
  843.         ' Out of blocks and we've still got more balls,
  844.         ' so rack 'em up again.
  845.         If (Not MoreBlocks) And (lblMisses < NumBalls) Then
  846.             SetupNextLevel
  847.         End If
  848.     End If
  849.     ' This is used to avoid multiple collision detections
  850.     ' for a single hit.
  851.     PrevPaddleCollision = PaddleCollision
  852. End Sub
  853.